home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Graphics / SMan / MorphOS / Source / ULP2mos.asm < prev    next >
Encoding:
Assembly Source File  |  2001-03-09  |  4.7 KB  |  196 lines

  1.  
  2. #    r0        volatile, may be used by function linkage
  3. #    r1        stack pointer
  4. #    r2        table of contents register
  5. #    r3    .. r4    volatile, pass 1st - 2nd int args, return 1st - 2nd ints
  6. #    r5  .. r10    volatile, pass 3rd - 8th int args
  7. #    r11        volatile, pass static chain if language needs it
  8. #    r12        volatile, used by dyn linker, exception handling
  9. #    r13 .. r31    saved
  10.  
  11.  
  12.  
  13. #    f0        volatile
  14. #    f1  .. f4    volatile, pass 1st - 4th float args, return 1st - 4th floats
  15. #    f5  .. f13    volatile, pass 5th - 13th float args
  16. #    f14 .. f31    saved
  17.  
  18. #    Use r23    as CurCnt
  19. #    Use r24    as MaxCnt (Constant value)
  20. #    Use r25    as LPixelBuf
  21. #    Use r26    as location within ColorTable32
  22. #    Use r27    as base address of ColorTable32
  23. #    Use r28    as BPP (that is, bytes per pixel)
  24.  
  25. #    r29    as RightEdge
  26. #    r30    as xtemp (integer)
  27.  
  28.  
  29.  
  30.  
  31.  
  32. #    Note that the following are constants, and independent of xtemp.
  33.  
  34. #    First the integers
  35. #    MaxCnt    in r24
  36. #    LPixelBuf in r25. It changes but need only be loaded 1 time.
  37. #    Base address of ColorTable32 in r27
  38. #    BPP in r28
  39.  
  40. #    Now the floats    (Newly defined)
  41.  
  42.  
  43. #    xRel in f15 (changes as DX is added in on each pass)
  44. #    Use f16    as value of yRel.  This is constant for each line.
  45. #    Use f17    as value that was stored in 40(r1).  It's Zi
  46. #    Use f18    as Zr.
  47. #    Use f19 as |Zr2| + |Zi2|    Only for comparing with Limit.
  48. #    Use f20    This is scratch and used shortly for 2Zi.
  49. #    Delta x    in f21
  50. #    Two    in f22
  51. #    Limit    in f23
  52. #    Use f24    as Zr2.  This is also a temporary value
  53.  
  54.  
  55. #vsc elf
  56.     .text
  57.     .sdreg    13
  58.     .global    UseLibP2
  59.     .align    4
  60. UseLibP2:
  61.     mflr    11
  62.     stw    11,4(1)    #Save return address
  63.     stwu    1,-80(1)      #Save stack pointer
  64.     fmr    16,1        #Transfer yrel from f1 to f16
  65.     lis    11,MaxCnt@ha
  66.     lwz    24,MaxCnt@l(11)    #MaxCnt in r24.
  67.     lis    11,LPixelBuf@ha
  68.     lwz    25,LPixelBuf@l(11)    #Get Location of LPixelBuf
  69.     lis    11,ColorTable32@ha
  70.     lwz    27,ColorTable32@l(11)    #Start of color table
  71.     lis    11,BPP@ha
  72.     lwz    28,BPP@l(11)             #Number bytes per pixel
  73.     lis    11,Factor@ha
  74.     lfd    25,Factor@l(11)    #Get Factor into f25
  75.     lis    11,Two@ha
  76.     lfd    22,Two@l(11)    #Get Two into f22 as constant
  77.     lis    11,Limit@ha
  78.     lfd    23,Limit@l(11)    #Get Limit into f23 as constant
  79.  
  80.     li    30,0        #xtemp = 0.
  81. # Convert xtemp to double fp.
  82.     lis    12,17200    #r12 = 0x4330
  83.  
  84.     lis    11,.l14@ha
  85.     stw    12,.l14@l(11)    #Place in buffer
  86.  
  87.     xoris    12,30,32768   #XOR with 0x8000
  88.  
  89.     lis    18,.l15@ha
  90.     stw    12,.l15@l(18)     #Store in high word of buffer
  91.  
  92.  
  93.     lis    11,.l14@ha
  94.     lfd    0,.l14@l(11)      #Get back as double
  95.  
  96.     lis    11,.l13@ha
  97.     lfd    10,.l13@l(11)
  98.     fsub    15,0,10        #Find (double)xtemp
  99.     lis    11,XCenter@ha
  100.     lfd    10,XCenter@l(11)    #f10 = XCenter
  101.     fsub    15,15,10    #xRel = xRel - XCenter
  102.     fdiv    15,15,25    #xRel = xRel/Factor
  103.     lis    11,DX@ha
  104.     lfd    21,DX@l(11)    #Get the real value of Delta x.
  105.     lis    11,RightEdge@ha
  106.     lwz    29,RightEdge@l(11)
  107.  
  108. Start:
  109.     fmr    18,15        #Initial value of Zr is xRel.
  110. #  The following line was moved before rather than after fmr f17,f16
  111. #  to give the fpu a break.
  112.     li    23,1        #Initialize CurCnt = 1
  113.     fmr    17,16        #yRel into f17 as initial Zi.
  114.     b    l3        #Check to see if to MaxCnt
  115. l2:    fmul    24,18,18    #Zr2 in f24
  116.     fmul    4,17,17        #Zi2 = Zi*Zi
  117.     fadd    19,24,4
  118.     fcmpu    0,19,23        #Compare with Limit in f23.
  119.     ble    0,l6
  120.  
  121. #The following section is not very time-critical as it is only reached once.
  122. #for each pixel
  123.     cmpwi    0,28,2        #See if BPP < 2
  124.     blt    0,l8
  125. l7:
  126.     slwi    10,23,2        #4 times CurCnt for offset in ColorTable32
  127.     add    26,27,10    #Find location of pixel color in ColorTable32
  128.     lwz    11,0(26)    #Get ARGB from ColorTable
  129.     stw    11,0(25)    #Store color in LPixelBuf
  130.     addi    25,25,4        #Point to next location in LPixelBuf
  131.     b    l1
  132. l8:    andi.    3,23,65535    #Prep for storage as UWORD
  133.     bl    PlotIt
  134. l9:    b    l1
  135. l6:
  136.     fmul    20,22,17    #Find 2*Zi (Two in f22)
  137.     fsub    10,24,4      #Zr2 = Zr2 - Zi2
  138.     fmul    17,20,18    #Find 2*Zi*Zr (temporary Zi)
  139.     addi    23,23,1       #Increment CurCnt
  140.     fadd    18,15,10    #New Zr = xRel + Zr2
  141.     fadd    17,16,17    #Zi = Zi + yRel
  142. l3:
  143.     cmpw    0,23,24        #See if CurCnt < MaxCnt
  144.     blt    0,l2        #Repeat until MaxCnt reached
  145.  
  146.     cmpwi    0,28,2        #See if BPP < 2
  147.     blt    0,l11
  148. l10:
  149.  
  150.     lis    12,4
  151.     addi    12,12,-4
  152.     add    26,27,12    #Find location of pixel color
  153.     lwz    11,0(26)      #Get color
  154.  
  155.     stw    11,0(25)    #Store color in LPixelBuf
  156.     addi    25,25,4        #Point to next pixel in buffer
  157.     b    l1        #Was l12
  158. l11:
  159.     lis    11,1
  160.     addi    3,11,-1        #ffff into r3 for PlotIt
  161.     bl    PlotIt
  162. l1:
  163.     fadd    15,15,21    #Find new value of xRel.
  164.     addi    30,30,1        #Increment xtemp.
  165.     cmpw    0,30,29        #See if to RightEdge
  166.  
  167.     blt    0,Start        #Repeat until row is done.
  168.     lis    11,LPixelBuf@ha
  169.     stw    25,LPixelBuf@l(11)  #New location in long pixel buffer
  170.     addi    1,1,80            #Balance Stack pointer
  171.     lwz    11,4(1)        #Get return address
  172.     mtlr    11
  173.     blr
  174.     .type    UseLibP2,@function
  175.     .size    UseLibP2,$-UseLibP2
  176.  
  177.     .globl    MaxCnt
  178.     .globl    RightEdge
  179.     .globl    XCenter
  180.     .globl    Factor
  181.     .globl    Limit
  182.     .globl    Two
  183.     .globl    LPixelBuf
  184.     .globl    ColorTable32
  185.     .globl    BPP
  186.     .globl    DX
  187.     .globl    PlotIt
  188.  
  189.     .section .rodata
  190.     .align    2
  191.     .align    3
  192. .l13:
  193.     .long    0x43300000,0x80000000
  194. .l14:    .word    0
  195. .l15:    .word    0,0,0
  196.